Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
{"status":400,"message":"missing client id"} response when using node-fetch

I am trying to get an oauth token from Twitch, and with this code:

import dotenv from 'dotenv';
dotenv.config();
import fetch from 'node-fetch';

let creds = {
        client_id:process.env.CLIENT_ID,
        client_secret:process.env.CLIENT_SECRET,
        grant_type:"client_credentials"
};

let request = {
    method:'POST',
    header:{ "Content-Type": "application/json" },
    body:creds
};
console.log(request);

fetch(process.env.AUTH_URL,request)
    .then (res => res.text())
    .then (text => console.log(text))

With my secret and client id where appropriate. However it keeps returning:

{"status":400,"message":"missing client id"}

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to stringify the body before sending it and headers instead of header.

let request = {
    method:'POST',
    headers:{ "Content-Type": "application/json" },
    body:JSON.stringify(creds)
};

Also, maybe use res.json() instead because the return data maybe json.

fetch(process.env.AUTH_URL,request)
    .then (res => res.json())
    .then (text => console.log(text))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda